//
//  LFMineYiJianController.m
//  LoveFruit
//
//  Created by xue-iOS-work on 16/9/23.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFMineYiJianController.h"

@interface LFMineYiJianController ()<UITextFieldDelegate>
// 文本输入框
@property (weak, nonatomic) IBOutlet UITextField *textFied;
// 用来接收用户输入的数据
@property(nonatomic,copy)NSString *text;

@end

@implementation LFMineYiJianController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 初始化导航控制器
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barBuutonItemWithTarget:self action:@selector(backItem) icon:@"btn_backItem" highlighticon:nil];
    // 右边
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonWithTitle:@"发送" image:nil style:UIBarButtonItemStylePlain target:self action:@selector(sendMessage)];
    UILabel *label = [UILabel labelWithText:@"意见反馈" andTextColor:[UIColor grayColor] andFontSize:18];
    label.frame = CGRectMake(0, 0, 20, 30);
    self.navigationItem.titleView = label;
    // 加载视图
    self.textFied.delegate = self;
}
#pragma mark - 初始化导航控制器
#pragma mark 返回按钮的点击
-(void)backItem{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark 发送按钮的点击
-(void)sendMessage{
    
    NSLog(@"发送给服务器的反馈数据为---%@",self.text);
    [SVProgressHUD showSuccessWithStatus:@"谢谢您的宝贵建议,已经上传到服务器!"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            [self dismissViewControllerAnimated:YES completion:nil];
    });
}
#pragma mark 文本框的代理

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    self.text = text;
    if (text.length>=300) {
        return NO;
    }
    return YES;
    
}
// 用户按回车键的时候调用
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"--%@---",self.text);
    [textField resignFirstResponder];
//    [SVProgressHUD showSuccessWithStatus:@"谢谢您的宝贵建议!"];
//    [SVProgressHUD dismissWithDelay:0.8];
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [self dismissViewControllerAnimated:YES completion:nil];
//    });
    
    return  YES;
}
@end
